/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Line2D;
import type.roadType;

/**
 *
 * @author JorgeLuis
 */
public class roadModel {
    
    
    private String      name        = "";
    private String      alias       = "";
    private int         id          = -1;
    private int         srcImage    = -1;
    private roadType    type        = roadType.RAMP;
    
    private hitoModel   hitoOne     = null;
    private hitoModel   hitoTwo     = null;
    
    private Point       positionOne = null;
    private Point       positionTwo = null;
         
    private boolean     seeName     = false;
    private boolean     seeDistance = false;
    
    // Draw
    
    private Color       color       = new Color(0,255,255);
    private Color       colorOriginal = color;
    private Color       colorContrary = new Color(
            Math.abs(color.getRed() - 255),
            Math.abs(color.getBlue() - 255),
            Math.abs(color.getGreen() - 255));
    
    private int distance            = 0;
    private String scale            = "";
    
    private Line2D line             = new Line2D.Float(0,0,0,0);

    public roadModel() {
    }
    
    

    public String getAlias() {
        return alias;
    }

    public Color getColor() {
        return color;
    }

    public Color getColorContrary() {
        return colorContrary;
    }

    public Color getColorOriginal() {
        return colorOriginal;
    }

    public int getDistance() {
        return distance;
    }

    public hitoModel getHitoOne() {
        return hitoOne;
    }

    public hitoModel getHitoTwo() {
        return hitoTwo;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public Point getPositionOne() {
        return positionOne;
    }

    public Point getPositionTwo() {
        return positionTwo;
    }

    public String getScale() {
        return scale;
    }

    public int getSrcImage() {
        return srcImage;
    }

    public roadType getType() {
        return type;
    }

    public boolean isSeeDistance() {
        return seeDistance;
    }

    public boolean isSeeName() {
        return seeName;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    public void setColorContrary(Color colorContrary) {
        this.colorContrary = colorContrary;
    }

    public void setColorOriginal(Color colorOriginal) {
        this.colorOriginal = colorOriginal;
        this.color = colorOriginal;
        this.colorContrary = new Color(
            Math.abs(colorOriginal.getRed() - 255),
            Math.abs(colorOriginal.getBlue() - 255),
            Math.abs(colorOriginal.getGreen() - 255));
    }

    public void setDistance(int distance) {
        this.distance = distance;
    }

    public void setHitoOne(hitoModel hitoOne) {
        this.hitoOne = hitoOne;
    }

    public void setHitoTwo(hitoModel hitoTwo) {
        this.hitoTwo = hitoTwo;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setPositionOne(Point positionOne) {
        this.positionOne = positionOne;
        if(this.positionOne != null && this.positionTwo != null){
            
            line.setLine(this.positionOne, this.positionTwo);
        }
    }

    public void setPositionTwo(Point positionTwo) {
        this.positionTwo = positionTwo;
        if(this.positionOne != null && this.positionTwo != null){
            
            line.setLine(this.positionOne, this.positionTwo);
        }
    }
    
    public void movePositionOne(int trasX, int trasY) {
        this.positionOne.translate(trasX, trasY);
        if(this.positionOne != null && this.positionTwo != null){            
            line.setLine(this.positionOne, this.positionTwo);
        }
    }
    
    public void movePositionTwo(int trasX, int trasY) {
        this.positionTwo.translate(trasX, trasY);
        if(this.positionOne != null && this.positionTwo != null){
            
            line.setLine(this.positionOne, this.positionTwo);
        }
    }

    public void setScale(String scale) {
        this.scale = scale;
    }

    public void setSeeDistance(boolean seeDistance) {
        this.seeDistance = seeDistance;
    }

    public void setSeeName(boolean seeName) {
        this.seeName = seeName;
    }

    public void setSrcImage(int srcImage) {
        this.srcImage = srcImage;
    }

    public void setType(roadType type) {
        this.type = type;
    }
    
     public boolean intersects(Point point){
         return line.intersects(point.x - 1.5, point.y - 1.5, 3, 3);
     }
     
     public void drawn(Graphics2D g2){
         
         Color colorOrigen  = g2.getColor();
         
         g2.setColor(color);
         g2.draw(line);
         
         if(seeName){
             
             g2.setColor(colorContrary);
             g2.drawString(name,(int) line.getBounds().getCenterX(),(int) line.getBounds().getCenterY());
             
         }
         
         if(seeDistance){
             
             g2.setColor(colorContrary);
             String disString = String.valueOf(distance);
             g2.drawString( disString,(int) line.getBounds().getCenterX(),(int) line.getBounds().getCenterY());
             
         }
         
         g2.setColor(colorOrigen);
     }
    
}
